﻿@model IEnumerable<JustMVCTest.Models.PO>
@using JustMVCTest.Models
           
@{
    ViewBag.Title = "POslist";
}
            <script type="text/javascript">
                function gup(name) {
                    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
                    var regexS = "[\\?&]" + name + "=([^&#]*)";
                    var regex = new RegExp(regexS);
                    var results = regex.exec(window.location.href);
                    if (results == null)
                        return "";
                    else
                        return results[1];
                }
            </script>

            <fieldset>
            <legend> Column Filter </legend>
<form name="pickform1" action="@Url.Action("Index", "POsList")"> 
                        
               <div style="margin:0px auto;">         <div style="float: left; width:220px">

                <input type  ="checkbox" name= "Description_Field" value="1" checked="checked" />Description <br /> 
                <input type  ="checkbox" name= "Delivery_Date_Field" value="1" checked="checked" /> Delivery Date    <br />
                <input type  ="checkbox" name= "Status_Field" value="1" checked="checked"  /> Status   <br />
                <input type  ="checkbox" name= "Requisitioner_Field" value="1" checked="checked" /> Requisitioner   <br />
                <input type  ="checkbox" name= "DeliveryDate_Req_Field" value="1" checked="checked" />Latest DeliveryDate Reqeust  <br />
                </div> 
                <div style="float: left;width:220px">
                <input type  ="checkbox" name= "Cost_Cent_Field" value="1" checked="checked" /> Cost Center    <br />
                <input type  ="checkbox" name= "Int_Order_Field" value="1" checked="checked" /> Int_Order   <br />
                <input type  ="checkbox" name= "Prof_Cent_Field" value="1" checked="checked" /> Prof_Cent   <br />
                <input type  ="checkbox" name= "Percentage_Field" value="1" checked="checked" /> Percentage  <br />
                <input type  ="checkbox" name= "cost_elem_Field" value="1" checked="checked" /> cost_elem    <br />
                 </div> 
                 <div style="float: left;width:220px">
                <input type  ="checkbox" name= "co_el_name_Field" value="1" checked="checked" /> co_el_name    <br />
                <input type  ="checkbox" name= "Vendor_Field" value="1" checked="checked" /> Vendor  <br />
                <input type  ="checkbox" name= "VendorName_Field" value="1" checked="checked" /> Vendor Name   <br />
                <input type  ="checkbox" name= "UM_Field" value="1" checked="checked" /> UM  <br />
                <input type  ="checkbox" name= "T_Curr_Field" value="1" checked="checked" /> T_Curr    <br />
                 </div> 
                 <div style="float: left;width:170px">
                <input type  ="checkbox" name= "Sch_Lin_Field" value="1" checked="checked" /> Sch_Lin   <br />
                <input type  ="checkbox" name= "Ord_Qty_Field" value="1" checked="checked" /> Ord_Qty   <br />
                <input type  ="checkbox" name= "Open_Qty_Field" value="1" checked="checked" /> Open_Qty   <br />
                <input type  ="checkbox" name= "Open_Amt_T_Field" value="1" checked="checked" /> Open_Amt_T  <br />
                 </div> 
                 <div>
                <input type  ="checkbox" name= "Order_Amt_Field" value="1" checked="checked" /> Order_Amt  <br />
                <input type  ="checkbox" name= "Open_Amt_L_Field" value="1" checked="checked" /> Open_Amt_L  <br />
                <input type  ="checkbox" name= "TSSC_Pending_Send_Date_Field" value="1" checked="checked" /> TSSC_Pending_Send_Date  <br />
                <input type  ="checkbox" name= "Purchase_O_Field" value="1" checked="checked" /> Purchase_O  <br />
                <input type="hidden" name="isfirstload" value="no" />              
             <br /> 
           <input style="font-size:small" type="submit" value="Apply" />     
           </div> </div></form>
   
       </fieldset>
                      <script type="text/javascript">
                          var param = gup("isfirstload");

                          var param7 = gup("Description_Field");

                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Description_Field.checked = true;
                          }
                          else {
                              document.pickform1.Description_Field.checked = false;
                          }

                          var param7 = gup("VendorName_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.VendorName_Field.checked = true;
                          }
                          else {
                              document.pickform1.VendorName_Field.checked = false;
                          }

                          var param7 = gup("Delivery_Date_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Delivery_Date_Field.checked = true;
                          }
                          else {
                              document.pickform1.Delivery_Date_Field.checked = false;
                          }
                          var param7 = gup("Status_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Status_Field.checked = true;
                          }
                          else {
                              document.pickform1.Status_Field.checked = false;
                          }
                          var param7 = gup("Requisitioner_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Requisitioner_Field.checked = true;
                          }
                          else {
                              document.pickform1.Requisitioner_Field.checked = false;
                          }
                          var param7 = gup("DeliveryDate_Req_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.DeliveryDate_Req_Field.checked = true;
                          }
                          else {
                              document.pickform1.DeliveryDate_Req_Field.checked = false;
                          }
                          var param7 = gup("Cost_Cent_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Cost_Cent_Field.checked = true;
                          }
                          else {
                              document.pickform1.Cost_Cent_Field.checked = false;
                          }
                          var param7 = gup("Int_Order_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Int_Order_Field.checked = true;
                          }
                          else {
                              document.pickform1.Int_Order_Field.checked = false;
                          }
                          var param7 = gup("Prof_Cent_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Prof_Cent_Field.checked = true;
                          }
                          else {
                              document.pickform1.Prof_Cent_Field.checked = false;
                          }
                          var param7 = gup("Percentage_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Percentage_Field.checked = true;
                          }
                          else {
                              document.pickform1.Percentage_Field.checked = false;
                          }
                          var param7 = gup("cost_elem_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.cost_elem_Field.checked = true;
                          }
                          else {
                              document.pickform1.cost_elem_Field.checked = false;
                          }
                          var param7 = gup("co_el_name_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.co_el_name_Field.checked = true;
                          }
                          else {
                              document.pickform1.co_el_name_Field.checked = false;
                          }
                          var param7 = gup("Vendor_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Vendor_Field.checked = true;
                          }
                          else {
                              document.pickform1.Vendor_Field.checked = false;
                          }
                          var param7 = gup("UM_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.UM_Field.checked = true;
                          }
                          else {
                              document.pickform1.UM_Field.checked = false;
                          }
                          var param7 = gup("T_Curr_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.T_Curr_Field.checked = true;
                          }
                          else {
                              document.pickform1.T_Curr_Field.checked = false;
                          }
                          var param7 = gup("Sch_Lin_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Sch_Lin_Field.checked = true;
                          }
                          else {
                              document.pickform1.Sch_Lin_Field.checked = false;
                          }
                          var param7 = gup("Ord_Qty_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Ord_Qty_Field.checked = true;
                          }
                          else {
                              document.pickform1.Ord_Qty_Field.checked = false;
                          }
                          var param7 = gup("Open_Qty_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Open_Qty_Field.checked = true;
                          }
                          else {
                              document.pickform1.Open_Qty_Field.checked = false;
                          }
                          var param7 = gup("Open_Amt_T_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Open_Amt_T_Field.checked = true;
                          }
                          else {
                              document.pickform1.Open_Amt_T_Field.checked = false;
                          }
                          var param7 = gup("Order_Amt_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Order_Amt_Field.checked = true;
                          }
                          else {
                              document.pickform1.Order_Amt_Field.checked = false;
                          }
                          var param7 = gup("Open_Amt_L_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Open_Amt_L_Field.checked = true;
                          }
                          else {
                              document.pickform1.Open_Amt_L_Field.checked = false;
                          }


                          var param7 = gup("TSSC_Pending_Send_Date_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.TSSC_Pending_Send_Date_Field.checked = true;
                          }
                          else {
                              document.pickform1.TSSC_Pending_Send_Date_Field.checked = false;
                          }
                          var param7 = gup("Purchase_O_Field");
                          if ((param7 == "1") || (param == "")) {
                              document.pickform1.Purchase_O_Field.checked = true;
                          }
                          else {
                              document.pickform1.Purchase_O_Field.checked = false;
                          }
            </script>  
       @(Html.Telerik().Grid<PO>(Model)
        .Name("POesGrid")
        .DataKeys(keys =>
        {
            keys.Add(p => p.PONumber);
            keys.Add(p => p.Item);
            keys.Add(p => p.Update_Num);
        })
        .ToolBar(commands => commands
            .Custom()
            .HtmlAttributes(new { id = "exportTableToCSV" })
            .Text("Export table to CSV")
            .Action("POsExportTableToCSV", "POsList", new
            {
                Delivery_Date_Field = Request.QueryString["Delivery_Date_Field"],
                Description_Field = Request.QueryString["Description_Field"],
                VendorName_Field = Request.QueryString["VendorName_Field"],
                Status_Field = Request.QueryString["Status_Field"],
                Requisitioner_Field = Request.QueryString["Requisitioner_Field"],
                DeliveryDate_Req_Field = Request.QueryString["DeliveryDate_Req_Field"],
                Cost_Cent_Field = Request.QueryString["Cost_Cent_Field"],
                Int_Order_Field = Request.QueryString["Int_Order_Field"],
                Prof_Cent_Field = Request.QueryString["Prof_Cent_Field"],
                Percentage_Field = Request.QueryString["Percentage_Field"],
                cost_elem_Field = Request.QueryString["cost_elem_Field"],
                co_el_name_Field = Request.QueryString["co_el_name_Field"],
                Vendor_Field = Request.QueryString["Vendor_Field"],
                UM_Field = Request.QueryString["UM_Field"],
                T_Curr_Field = Request.QueryString["T_Curr_Field"],
                Sch_Lin_Field = Request.QueryString["Sch_Lin_Field"],
                Ord_Qty_Field = Request.QueryString["Ord_Qty_Field"],
                Open_Qty_Field = Request.QueryString["Open_Qty_Field"],
                Open_Amt_T_Field = Request.QueryString["Open_Amt_T_Field"],
                Order_Amt_Field = Request.QueryString["Order_Amt_Field"],
                Open_Amt_L_Field = Request.QueryString["Open_Amt_L_Field"],
                TSSC_Pending_Send_Date_Field = Request.QueryString["TSSC_Pending_Send_Date_Field"],
                Purchase_O_Field = Request.QueryString["Purchase_O_Field"],
                isfirstload = Request.QueryString["isfirstload"] 
            })
                                )
        .Columns(columns =>
        { 
            columns.Template(@<form name="pickform" style="margin:0px;padding:0px" action="@Url.Action("Edit", "POsEdit")"> 
            <input type="hidden" value="@item.Item" name= "Item"/> <input type="hidden" value="@item.PONumber" name= "PONumber"/>
             <input style="padding:0;vertical-align:middle;text-align:center;font-size:small;height:30px" type="submit" value="Edit PO" /> </form>).Title("Commands").Width(100);
            
            columns.Template(@<form name="pickform" style="margin:0px;padding:0px" action="@Url.Action("Index", "History")"> 
            <input type="hidden" value="@item.Item" name= "Item"/> <input type="hidden" value="@item.PONumber" name= "PONumber"/>
             <input style="padding:0;vertical-align:middle;text-align:center;font-size:small;height:30px" type="submit" value="History" /> </form>).Width(100);
            columns.Bound(o => o.PONumber).Width(150);
            columns.Bound(o => o.Item).Width(100);
            if ((bool)ViewData["Status_Field"] == true)
            {
                columns.Template(@<script type="text/javascript">
                                   var x = @item.Status
                                   if (x == '1') {
                                       document.write("Pending Close");
                                   }
                                   if (x == '2') {
                                       document.write("Pending Delivery Date");
                                   }
                                   if (x == '0') {
                                       document.write("Open");
                                   }
                                   if (x == '99') {
                                       document.write("Closed");
                                   }

                    </script>).Title("Status").Width(200);
            }


            if ((bool)ViewData["Description_Field"] == true)
            {
                columns.Bound(o => o.Descr).Width(600);
            }
            if ((bool)ViewData["Delivery_Date_Field"] == true)
            {
                columns.Bound(o => o.DeliveryDate).Width(200).Format("{0:d}");
            }




            if ((bool)ViewData["Requisitioner_Field"] == true)
            {
                columns.Bound(o => o.Requisitioner).Width(100);
            }

            if ((bool)ViewData["DeliveryDate_Req_Field"] == true)
            {
                columns.Template(@<script type="text/javascript">
                                   var x = @item.Status
                                   if (x == '1') {
                                       document.write("");
                                   }
                                   if (x == '2') {
                                       document.write("@item.DeliveryDate_Req.ToShortDateString()");
                                   }
                                   if (x == '0') {
                                       document.write("");
                                   }
                                   if (x == '99') {
                                       document.write("");
                                   }

                    </script>).Title("Delivery Date Request").Width(150);
            }
            
            if ((bool)ViewData["Cost_Cent_Field"] == true)
            {
                columns.Bound(o => o.Cost_Cent).Width(150);
            }
             
            if ((bool)ViewData["Int_Order_Field"] == true)
            {
                columns.Bound(o => o.Int_Order).Width(150);
            }
            if ((bool)ViewData["Prof_Cent_Field"] == true)
            {
                columns.Bound(o => o.Prof_Cent).Width(150);
            }
            if ((bool)ViewData["Percentage_Field"] == true)
            {
                columns.Bound(o => o.Percentage).Width(150);
            }
            if ((bool)ViewData["cost_elem_Field"] == true)
            {
                columns.Bound(o => o.cost_elem).Width(150);
            }
            if ((bool)ViewData["co_el_name_Field"] == true)
            {
                columns.Bound(o => o.co_el_name).Width(200);
            }
            if ((bool)ViewData["Vendor_Field"] == true)
            {
                columns.Bound(o => o.Vendor).Width(100);
            }
            if ((bool)ViewData["VendorName_Field"] == true)
            {
                columns.Bound(o => o.VendorName).Width(300);
            }
            if ((bool)ViewData["UM_Field"] == true)
            {
                columns.Bound(o => o.UM).Width(100);
            }
            if ((bool)ViewData["T_Curr_Field"] == true)
            {
                columns.Bound(o => o.T_Curr).Width(150);
            }
            if ((bool)ViewData["Sch_Lin_Field"] == true)
            {
                columns.Bound(o => o.Sch_Lin).Width(100);
            }
            if ((bool)ViewData["Ord_Qty_Field"] == true)
            {
                columns.Bound(o => o.Ord_Qty).Width(100);
            }
            if ((bool)ViewData["Open_Qty_Field"] == true)
            {
                columns.Bound(o => o.Open_Qty).Width(100);
            }
            if ((bool)ViewData["Open_Amt_T_Field"] == true)
            {
                columns.Bound(o => o.Open_Amt_T).Width(100);
            }
            if ((bool)ViewData["Order_Amt_Field"] == true)
            {
                columns.Bound(o => o.Order_Amt).Width(100);
            }
            if ((bool)ViewData["Open_Amt_L_Field"] == true)
            {
                columns.Bound(o => o.Open_Amt_L).Width(100);
            }
            if ((bool)ViewData["TSSC_Pending_Send_Date_Field"] == true)
            {
                columns.Bound(o => o.TSSC_Pending_Send_Date).Width(100);
            } 
            if ((bool)ViewData["Purchase_O_Field"] == true)
            {
                columns.Bound(o => o.Purchase_O).Width(100);
            }
        })

        .CellAction(cell =>
        {
            if (cell.Column.Member == "Status")
            {
                PO po = cell.DataItem;
            }
        })


        .Pageable(paging => paging.PageSize(7))
        .Sortable()
        .Scrollable(c => c.Height("300px"))
        .Resizable(resizing => resizing.Columns(true))


                                            )